package com.tairanchina.joat.groovy;

import com.tairanchina.joat.PluginManagerDe;
import com.tairanchina.joat.exception.JoatLifecycleException;
import groovy.lang.GroovyClassLoader;

import java.io.File;

/**
 * Created by 周靖捷 on 2016/10/10.
 */
public class GroovyPluginManagerDe extends PluginManagerDe {
    GroovyClassLoader groovyClassLoader;

    File pluginCacheFolder;

    public GroovyPluginManagerDe() {
    }

    public GroovyPluginManagerDe(File pluginCacheFolder) {
        this.pluginCacheFolder = pluginCacheFolder;
    }

    public GroovyPluginManagerDe(String pluginCacheFolderDir) {
        this.pluginCacheFolder = new File(pluginCacheFolderDir);
    }

    public void registerScriptClass(String fullClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    }

    @Override
    public void init() throws JoatLifecycleException {
        groovyClassLoader = new GroovyClassLoader(this.getClass().getClassLoader());
        if (!pluginCacheFolder.exists()) {
            if (!pluginCacheFolder.mkdirs())
                throw new JoatLifecycleException("Plugin Cache Folder Does Not Exists!");
        }
        if (!pluginCacheFolder.isDirectory()) {
            throw new JoatLifecycleException("Plugin Cache Folder Dir Is Not A Directory!");
        }
        super.init();
    }



    public void load() throws JoatLifecycleException {

    }

    public void run() throws JoatLifecycleException {

    }
}
